package producerAndConsumer;

import java.util.concurrent.*;

/**
 * <pre>
 * 功能描述：生产者+消费者+阻塞队列
 * </pre>
 *
 * @author: 李明杰
 * @date: 2023/4/29 16:39
 */
public class MainThread {
    public static void main(String[] args) {
        ExecutorService exec = new ThreadPoolExecutor(10, 20, 1000, TimeUnit.MILLISECONDS,
                new ArrayBlockingQueue<Runnable>(5), Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy());

        for (int i = 0; i < 100; i++) {//使用线程池模拟生成者生产数据
            exec.execute(new Producer());
        }

        for (int i = 0; i < 2; i++) {//启动两个消费者线程
            new Consumer().start();
        }
    }
}

